$(function(){
  $(".eList dl").hover(function() {
	$(this).addClass("hover");
  }, function() {
	$(this).removeClass("hover");
  });
  
  $("a[name='delete'], input[name='delete']").click(function(){
    if(confirm("确定要删除吗？") == true) return true;  
	else return false;  
  });
});

function eDivTag(div, num) {
  $(".eTag li").removeClass("eSelected");
  $(div).parent().addClass("eSelected");
  $(".eBorder").hide();
  $(".eBorder:eq("+ num +")").show();
}

function selectID(ID) {
  if(ID == 1)
	$("input[name='checkID[]']").attr("checked", true);
  else if(ID == 0)
	$("input[name='checkID[]']").attr("checked", false);
  else if(ID == 2)
	$("input[name='checkID[]']").each(function(i){
	  if($(this).attr("checked")) $(this).attr("checked", false);
	  else $(this).attr("checked", true);
	})
}

function alertCoord() {
  var winWidth = ($(window).width() - 200) / 2;
  var winHeight = ($(window).height() - 100) / 2;
  var bodyWidth = $("#eBody").width() / 2;
  var bodyHeight = $("#eBody").height() / 2;
  var newWidth = winWidth - bodyWidth;
  var newHeight = winHeight - bodyHeight;
  
  if(winHeight < bodyHeight) newHeight = 10;
  
  $("#eBody").animate({ left: newWidth, top: newHeight }, 0, function(){
	$(this).show();	
  });
}

function ekind() {
  KindEditor.ready(function(K) {
	  K.create('textarea[id="content"]', {
		  allowFileManager : false,
		  langType : 'en',
		  height: 550,
		  width: "100%",
		  resizeMode: 0,
		  shadowMode : false,
		  autoSetDataMode: false,
		  allowPreviewEmoticons : false
	  });
  });
}

function submitAll(url) {
  delSize = $("input[name='checkID[]']:checked").size();
  if(delSize > 0) {
	$("#Romeo").attr("action", url).submit();
  }
  else
	alert('请选择删除的内容');
}

function Operation(D) {
  $(D).parent().find(".eOperation").click(function(){
	$(this).hide();
  }).hover(function(){
	$(this).show();
  }, function(){
	$(this).hide();
  }).show();
}

function delPic() {
  $("#newspic").val("");
  $("#imgPreview").attr("src", "/style/images/pictures.png");
}

function onSelect(D, num) {
  var htmlOption = "";
  $.ajax({
	url: "/mang/product/path?id="+$(D).val(),
	cache: false,
	success: function(html){
	  if(num == 2) {
		$("#path3").html("");
	  }
	  
	  $("#path" + num).html("");
	  
	  if(html == "") {
	    $("#cid").val($(D).val());
		$("#path").val($(D).find(":selected").attr("path"));
	  }
	  else {
		$("#path" + num).html(html);
		$("#path" + num).width($("#path" + num).width())
	  }
	}
  });
}

function onSelectAll(path) {
  pathSplit = path.split(".");
  $("#path1").find("option[value='"+pathSplit[3]+"']").attr("selected", true);
  onSelect($("#path1"), 2);
  onSelect($("#path2"), 0);
}

function delImg(D) {
  if(confirm("Whether deleted?")) {
    $(D).parent().remove();
	return true;
  }
  else return false;
}